<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>组织架构 - 人员管理</title>

    <link href='http://fonts.useso.com/css?family=Open+Sans:400,300,400italic,700' rel='stylesheet' type='text/css'>
    <link href="./css/font-awesome.min.css" rel="stylesheet">
    <link href="./css/bootstrap.min.css" rel="stylesheet">
    <link href="./css/templatemo-style.css" rel="stylesheet">
    <link href="./css/jquery-confirm.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script src="./js/jquery-1.11.2.min.js"></script>      <!-- jQuery -->
    <script type="text/javascript" src="./js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript" src="./js/jquery-confirm.js"></script>
<script type="text/javascript" src="./js/jquery.page.js"></script>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

  </head>
  <body>
    <!-- Left column -->
    <div class="templatemo-flex-row">
      <div class="templatemo-sidebar">
        <header class="templatemo-site-header">
          <div class="square"></div>
          <h1>组织架构</h1>
        </header>

        <!-- Search box -->
        <form class="templatemo-search-form" role="search">
          <div class="input-group">
              <button type="submit" class="fa fa-search"></button>
              <input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
          </div>
        </form>
        <div class="templatemo-content">
      <ul id="treeDemo" class="ztree"></ul>
    </div>
      </div>
      <!-- Main content -->
      <div class="templatemo-content col-1 light-gray-bg">
        <div class="templatemo-top-nav-container">
          <div class="row">
            <nav class="templatemo-top-nav col-lg-12 col-md-12">
              <ul class="text-uppercase">
                <li><a href="home" >主页</a></li>
                <li><a id="dep" href="#">部门管理</a></li>
                <li><a id="person" href="#" class="active">人员管理</a></li>
                <li><a href="logout">退出</a></li>
              </ul>
            </nav>
          </div>
        </div>
        <div class="templatemo-content-container">
        <div><a id="tabel" href="#" class="templatemo-edit-btn"><span><img src="./images/t01.png"/></span>添加人员</a></div>
          <div class="templatemo-content-widget no-padding">
            <div class="panel panel-default table-responsive">
              <table
							class="table table-striped table-bordered templatemo-user-table">
							<thead>
								<tr>
									<td><a href="" class="white-text templatemo-sort-by">编号
											<span class="caret"></span>
									</a></td>
									<td><a href="" class="white-text templatemo-sort-by">姓名<span
											class="caret"></span></a></td>
									<td><a href="" class="white-text templatemo-sort-by">联系方式
											<span class="caret"></span>
									</a></td>
									<td><a href="" class="white-text templatemo-sort-by">性别
											<span class="caret"></span>
									</a></td>
									<td><a href="" class="white-text templatemo-sort-by">行政工号
											<span class="caret"></span>
									</a></td>
									<td><a href="" class="white-text templatemo-sort-by">所属部门
											<span class="caret"></span>
									</a></td>
									<td><a href="" class="white-text templatemo-sort-by">职务
											<span class="caret"></span>
									</a></td>
									<td  align="center">操作</td>
									<td  align="center">删除</td>
								</tr>
							</thead>
							<tbody id="orgTb">

							</tbody>
						</table>
            </div>
            <div class="tcdPageCode"></div>
          </div>
          <footer class="text-center">
            <p>Copyright &copy; 2015 宁波市政务云计算中心</p>
          </footer>
        </div>
      </div>
    </div>

   <!-- Templatemo Script -->
<script type="text/javascript">

     var setting = {
      data: {
        simpleData: {
          enable: true
        }
      }
    }; 

    /* var zNodes =[
      { id:1, pId:0, name:"公安局", url:"orglist",target:"_self",open:true, iconOpen:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:11, pId:1, name:"交管局",  url:"orglist",target:"_self",open:true,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:12, pId:1, name:"交警局",  url:"orglist",target:"_self",open:true,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:121, pId:12, name:"支队1",  url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:122, pId:12, name:"支队2",  url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:1211, pId:121, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:1212, pId:121, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:1221, pId:122, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:1222, pId:122, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:2, pId:0, name:"工商局",  url:"orglist",target:"_self",open:true, iconOpen:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:21, pId:2, name:"科室1",  url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:22, pId:2, name:"科室2", url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:211, pId:21, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:212, pId:21, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:221, pId:22, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:222, pId:22, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:3, pId:0, name:"司法局",  url:"orglist",target:"_self",open:true, iconOpen:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:31, pId:3, name:"科室1", url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:32, pId:3, name:"科室2",url:"personlist",target:"_self",open:false, icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:311, pId:31, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:312, pId:31, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:321, pId:32, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:322, pId:32, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
    ]; */

    $(document).ready(function(){
       // alert("1");
    	  $.ajax(
 	    	    {url:"listpersontree", 
 	        	 dataType:"json",
 	        	 contentType: "application/x-www-form-urlencoded; charset=utf-8", 
 	        	 type:"POST",
 				success:function (data) {
 					$.fn.zTree.init($("#treeDemo"), setting, data);
 	        		   
 	    },
 	    error:function(){alert("出错啦！");}});

    
     $.ajax(
	    	    {url:"listperson", 
	        	 dataType:"json",
	        	 contentType: "application/x-www-form-urlencoded; charset=utf-8", 
	        	 type:"POST",
				success:function (data) {
					 $.each(data, function(index, item) {
  		        		  // alert(item["id"]);
  		        		   //alert(index);
  		        		  if(index<8){
  		        		  var sex=" ";
  		        		  var admin="";
  		        		  if(item["sex"]==1) sex="男";
  		        		  else sex="女";
  		        		 if(item["adminflag"]==1) admin="取消管理员";
 		        		  else admin="设为管理员";
  		        		 var orgTb=document.getElementById("orgTb");
  	 	        			var row=orgTb.insertRow(index);
  	 	        			row.insertCell(0).innerHTML=item["id"];
  	 	        			row.insertCell(1).innerHTML=item["name"];
  	 	        			row.insertCell(2).innerHTML=item["phone"];
  	 	        			row.insertCell(3).innerHTML=sex;
  	 	        			row.insertCell(4).innerHTML=item["sn"];
  	 	        			row.insertCell(5).innerHTML=item["org"];
  	 	        			row.insertCell(6).innerHTML=item["pos"];
  	 	        			row.insertCell(7).innerHTML="<a  onclick=\"edit("+item["id"]+")\" class=\"templatemo-edit-btn\">编辑</a> <a  onclick=\"setasadmin("+item["id"]+","+item["pid"]+","+item["oid"]+","+item["adminflag"]+")\" class=\"templatemo-edit-btn\">"+admin+"</a>";
  	 	        			row.insertCell(8).innerHTML="<a  onclick=\"del("+item["id"]+")\" class=\"templatemo-link\">删除</a>";  
  		        		  }});  
	        		  if(data!=null&& data!=undefined && data!=""){	 
	        	$(".tcdPageCode").createPage({
   			pageCount:Math.ceil(data.length/8.0),
  				current:1,
   			backFn:function(p){
   				var tb=document.getElementById("orgTb");
   				var t=data.length-(Math.ceil(data.length/8.0)-1)*8;
						for(var i=7;i>=t;i--){
							for(var j=0;j<9;j++)
							tb.rows[i].cells[j].style.display="";
							}
   				 $.each(data, function(index, item) {
		        		  // alert(item["id"]);
		        		  if(index>=8*(p-1)&&index<8*p){
		        			// alert(index);
		        		 var sex=" ";
  		        		  var admin="";
  		        		  if(item["sex"]==1) sex="男";
  		        		  else sex="女";
  		        		 if(item["adminflag"]==1) admin="取消管理员";
 		        		  else admin="设为管理员";
		        		  var row=index%8;
		        		//  alert(row);
		        		
	 	        			//var row=orgTb.insertRow(index);
	 	        		tb.rows[row].cells[0].innerHTML=item["id"];
	 	        		tb.rows[row].cells[1].innerHTML=item["name"];
	 	        		tb.rows[row].cells[2].innerHTML=item["phone"];
	 	        		tb.rows[row].cells[3].innerHTML=sex;
	 	    			tb.rows[row].cells[4].innerHTML=item["sn"];
	 					tb.rows[row].cells[5].innerHTML=item["org"];
						tb.rows[row].cells[6].innerHTML=item["pos"];
						tb.rows[row].cells[7].innerHTML="<a  onclick=\"edit("+item["id"]+")\" class=\"templatemo-edit-btn\">编辑</a> <a onclick=\"setasadmin("+item["id"]+","+item["pid"]+","+item["oid"]+","+item["adminflag"]+")\" class=\"templatemo-edit-btn\">"+admin+"</a>";
						tb.rows[row].cells[8].innerHTML="<a  onclick=\"del("+item["id"]+")\" class=\"templatemo-link\">删除</a>";  
		        		  }
		        		  }); 
   				 if(p==Math.ceil(data.length/8.0)){
						var t=data.length-(p-1)*8;
						for(var i=7;i>=t;i--){
							for(var j=0;j<9;j++)
							tb.rows[i].cells[j].style.display="none";
							}
						} 	       
   			}
					 });
	        		  } else {
	        			  $.confirm({
	        				   keyboardEnabled: true,
	    	             	    //title: false, // hides the title.
	    	             	    content: '该部门下没有人员，请添加！',
	    	             	    cancelButton: false, // hides the cancel button.
	    	             	    confirmButtonClass: 'btn-info',
	    	             	   autoClose: 'confirm|3000'
	    	             	});
		        		  }
       		  
   },
   error:function(){alert("出错啦！");}});
}); 
    $("#dep").click(function(){  
    	location.href = "orglist?"+Math.random();
     });
    $("#dep").click(function(){  
    	location.href = "orglist?"+Math.random();
     });
    $("#person").click(function(){  
    	location.href = "personlist?"+Math.random();
     });
 $("#tabel").click(function(){
       
    	
    	$.confirm({
    		keyboardEnabled: true,
    	    title: '添加人员',
    	    content: function($obj){
    	    	return $.ajax({
    	             url:"getparentorgpos",
    	             dataType:"json",
    	             type:"POST",
    	             success:function (data) {
    	            	 var parentorg="";
    	            	 var pos="";
    	             	 $.each(data[0], function(index, item) {
    	             		parentorg=parentorg+"'<option value=\""+item["id"]+"\">"+item["name"]+"</option>'"
    	             		// alert(parentorg);
    	             	 });
    	             	 $.each(data[1], function(index, item) {
     	             		pos=pos+"'<option value=\""+item["id"]+"\">"+item["name"]+"</option>'"
     	             		// alert(parentorg);
     	             	 });
    	             	 $obj.setContent('  <form id ="personadd"  class="templatemo-login-form" method="post" >'+
    	                 	    '<div class="row form-group">'+
    	                        '<div class="col-lg-6 col-md-6 form-group">'+                  
    	                   ' <label for="inputFirstName">姓名</label>'+
    	                    '<input type="text" class="form-control" name="name" placeholder="张三"> '+                 
    	                '</div>'+
    	                '<div class="col-lg-6 col-md-6 form-group"> '+                 
    	                   ' <label for="inputLastName">行政工号</label>'+
    	                   ' <input type="text" class="form-control" name="sn" placeholder="NB001"> '+                 
    	                '</div>'+ 
    	              '</div>'+
    	              '<div class="row form-group">'+
    	              '<div class="col-lg-6 col-md-6 form-group">'+                  
    	         		' <label for="inputFirstName">联系方式</label>'+
    	          		'<input type="text" class="form-control" name="phone" placeholder="123456"> '+                 
    	        		'</div>'+
    	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
    	         		'<label class="control-label templatemo-block">性别</label>'+
    	         		'   <select name="sex" class="form-control">'+
    	                           '<option value="1">男</option>'+
    	                            '<option value="2">女</option>'+  
    	                          '</select>'+                 
    	        		'</div>'+ 
    	        		'</div>'+
    	        		'<div class="row form-group">'+
    	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
    	        		'<label class="control-label templatemo-block">所属部门</label>'+
    	         		'   <select name="oid" class="form-control">'+
    	         		parentorg +                     
    	                          '</select>'+                 
    	        		'</div>'+ 
    	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
    	        		'<label class="control-label templatemo-block">担任职务</label>'+
    	         		'   <select name="pid" class="form-control">'+
    	         		pos +                     
    	                          '</select>'+                 
    	        		'</div>'+ 
    	        		'</div>'+
    	        		'</form>');
    	             },
    	             error:function () {
    	             	$.confirm({
    	             		keyboardEnabled: true,
    	             	    title: false, // hides the title.
    	             	    content: '获取信息失败，请重新获取！',
    	             	    cancelButton: false, // hides the cancel button.
    	             	    closeIcon: false // hides the close icon.
    	             	});
    	             }
    	         });   
    	         },
    	    confirmButtonClass: 'btn-info',
    	    cancelButtonClass: 'btn-danger',
    	    confirm: function(){ 
        	    $.ajax({
                url:"addperson",
                dataType:"json",
                type:"POST",
                data:$("#personadd").serializeArray(),
                success:function (data) {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: '添加成功',
                	    content: '添加人员成功！',
                	    autoClose: 'confirm|3000'
                	});
                },
                error:function () {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: false, // hides the title.
                	    content: '添加人员失败，请重新添加！',
                	    cancelButton: false, // hides the cancel button.
                	    closeIcon: false // hides the close icon.
                	});
                }
            }); 
    	    	
    	    }
    	});
     });
   function edit(pid){
    	$.confirm({
    		keyboardEnabled: true,
    	    title: '编辑人员',
    	    content: function($obj){
    	    	return $.ajax({
    	             url:"editperson",
    	             data:{"pid":pid},
    	             dataType:"json",
    	             type:"POST",
    	             success:function (data) {
        	             var sex="";
        	           if(data[0]["sex"]==1) {sex=sex+"'<option selected=\"selected\" value=\""+1+"\" >男</option> <option  value=\""+2+"\" >女</option>'";}
      	             else sex=sex+"'<option selected=\"selected\" value=\""+2+"\" >女</option> <option  value=\""+1+"\" >男</option>'";
        	           //  alert(data);
        	           var parentorg="";
    	            	 var pos="";
    	             	 $.each(data[1], function(index, item) {
        	             	 if(data[0]["org"]==item["name"])
    	             		parentorg=parentorg+"'<option selected=\"selected\" value=\""+item["id"]+"\">"+item["name"]+"</option>'";
    	             		else parentorg=parentorg+"'<option  value=\""+item["id"]+"\">"+item["name"]+"</option>'";
    	             		// alert(parentorg);
    	             	 });
    	             	 $.each(data[2], function(index, item) {
    	             		 if(data[0]["pos"]==item["name"])
    	    	             		pos=pos+"'<option selected=\"selected\" value=\""+item["id"]+"\">"+item["name"]+"</option>'";
    	    	             		else pos=pos+"'<option  value=\""+item["id"]+"\">"+item["name"]+"</option>'";
     	             	 });
        	           $obj.setContent('  <form id ="personedit"  class="templatemo-login-form" method="post" >'+
   	                 	    '<div class="row form-group">'+
   	                        '<div class="col-lg-6 col-md-6 form-group">'+                  
   	                   ' <label for="inputFirstName">姓名</label>'+
   	                    '<input type="text" class="form-control" name="name" value=\"'+data[0]["name"]+'\"> '+  
   	                 '<input type="hidden" class="form-control" name="id" value=\"'+data[0]["id"]+'\"> '+  
   	              '<input type="hidden" class="form-control" name="pastoid" value=\"'+data[0]["oid"]+'\"> '+  
   	           '<input type="hidden" class="form-control" name="pastpid" value=\"'+data[0]["pid"]+'\"> '+                 
   	                '</div>'+
   	                '<div class="col-lg-6 col-md-6 form-group"> '+                 
   	                   ' <label for="inputLastName">行政工号</label>'+
   	                   ' <input type="text" class="form-control" name="sn" value=\"'+data[0]["sn"]+'\"> '+                 
   	                '</div>'+ 
   	              '</div>'+
   	              '<div class="row form-group">'+
   	              '<div class="col-lg-6 col-md-6 form-group">'+                  
   	         		' <label for="inputFirstName">联系方式</label>'+
   	          		'<input type="text" class="form-control" name="phone" value=\"'+data[0]["phone"]+'\"> '+                 
   	        		'</div>'+
   	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
   	         		'<label class="control-label templatemo-block">性别</label>'+
   	         		'   <select name="sex" class="form-control">'+
   	                          sex+
   	                          '</select>'+                 
   	        		'</div>'+ 
   	        		'</div>'+
   	        		'<div class="row form-group">'+
   	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
   	        		'<label class="control-label templatemo-block">所属部门</label>'+
   	         		'   <select name="oid" class="form-control">'+
   	         		parentorg +                     
   	                          '</select>'+                 
   	        		'</div>'+ 
   	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
   	        		'<label class="control-label templatemo-block">担任职务</label>'+
   	         		'   <select name="pid" class="form-control">'+
   	         		pos +                     
   	                          '</select>'+                 
   	        		'</div>'+ 
   	        		'</div>'+
   	        		'</form>');
   	             },
    	             error:function () {
    	             	$.confirm({
    	             		keyboardEnabled: true,
    	             	    title: false, // hides the title.
    	             	    content: '获取信息失败，请重新获取！',
    	             	    cancelButton: false, // hides the cancel button.
    	             	    closeIcon: false // hides the close icon.
    	             	});
    	             }
    	         });   
    	         },
    	    confirmButtonClass: 'btn-info',
    	    cancelButtonClass: 'btn-danger',
    	    confirm: function(){ 
        	    $.ajax({
                url:"confirmeditperson",
                dataType:"json",
                type:"POST",
                data:$("#personedit").serializeArray(),
                success:function (data) {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: '修改成功',
                	    content: '修改人员信息成功！',
                	    autoClose: 'confirm|3000'
                	});
                },
                error:function () {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: false, // hides the title.
                	    content: '修改人员信息失败，请重新修改！',
                	    cancelButton: false, // hides the cancel button.
                	    closeIcon: false // hides the close icon.
                	});
                }
            }); 
    	    	
    	    }
    	});
     }
   function del(pid){
   	$.confirm({
   		keyboardEnabled: true,
   	    title: '删除人员',
   	    content: '此操作不可撤销，确定删除该人员？',
   	    confirmButtonClass: 'btn-info',
   	    cancelButtonClass: 'btn-danger',
   	    confirm: function(){ 
       	    $.ajax({
               url:"delperson",
               dataType:"json",
               type:"POST",
               data:{"pid":pid},
               success:function (data) {
               	$.confirm({
               		keyboardEnabled: true,
               	    title: '删除成功',
               	    content: '删除人员成功！',
               	    autoClose: 'confirm|3000'
               	});
               },
               error:function () {
               	$.confirm({
               		keyboardEnabled: true,
               	    title: false, // hides the title.
               	    content: '删除人员失败，请重新操作！',
               	    cancelButton: false, // hides the cancel button.
               	    closeIcon: false // hides the close icon.
               	});
               }
           }); 
   	    	
   	    }
   	});
    }
   function setasadmin(id,pid,oid,adminflag){
	   var admin="";
		 if(adminflag==1) admin="取消管理员";
		  else admin="设为管理员";
	   	$.confirm({
	   		keyboardEnabled: true,
	   	    title: '管理员设置',
	   	    content: '确定将该人员'+admin+'？',
	   	    confirmButtonClass: 'btn-info',
	   	    cancelButtonClass: 'btn-danger',
	   	    confirm: function(){ 
	       	    $.ajax({
	               url:"adminset",
	               dataType:"json",
	               type:"POST",
	               data:{"id":id,"pid":pid,"oid":oid},
	               success:function (data) {
	               	$.confirm({
	               		keyboardEnabled: true,
	               	    title: '操作成功',
	               	    content: '操作成功！',
	               	    autoClose: 'confirm|3000'
	               	});
	               },
	               error:function () {
	               	$.confirm({
	               		keyboardEnabled: true,
	               	    title: false, // hides the title.
	               	    content: '操作失败，请重新操作！',
	               	    cancelButton: false, // hides the cancel button.
	               	    closeIcon: false // hides the close icon.
	               	});
	               }
	           }); 
	   	    	
	   	    }
	   	});
	    }
   </script>
  </body>
</html>
